package org.genntii.warehousesystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.genntii.warehousesystem.Exception.ParamErrorException;
import org.genntii.warehousesystem.domain.entity.Type;
import org.genntii.warehousesystem.mapper.TypeMapper;
import org.genntii.warehousesystem.service.TypeService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements TypeService {

    @Resource
    private TypeMapper typeMapper;

    @Override
    public void add(String typeName) {
        Type type = new Type();
        type.setTypeName(typeName);
        typeMapper.insert(type);
    }

    @Override
    public void del(int id) {
        Type type = typeMapper.selectById(id);
        if (type == null){
            throw new ParamErrorException("参数错误");
        }
        typeMapper.deleteById(id);
    }

    @Override
    public List<Type> showAllByPage(int page) {
        return typeMapper.showAllByPage(10*(page-1));
    }

    @Override
    public List<Type> showAllType() {
        return typeMapper.showAllType();
    }
}
